-- Log
--
local trace = trace
local main_ctx = main_ctx
local bret = import('bt/bt_plugin/behavior3/behavior_ret')

---@type BehaviorNodeDefine
local M = {
    name = "Log",
    type = "Action",
    desc = "打印日志",
    args = {
        {
            name = "message",
            type = "string",
            desc = "日志"
        },
        { name = 'isMainCtx', type = 'boolean?', desc = '是否输出到控制台' },
        { name = 'isCurMainTarget', type = 'boolean?', desc = '是否输出当前目标' },
    },
    input = { "运行时间?", "总计时间?" },
    run = function(node, env, runTime, totalTime)
        local isMainCtx = node.args.isMainCtx or false
        local isCurMainTarget = node.args.isCurMainTarget or false
        local message = node.args.message
        if isCurMainTarget then
            local owner = env.owner
            local curMainTarget = owner:get_curMainTarget()
            if runTime and totalTime then
                runTime = math.floor(runTime)
                totalTime = math.floor(totalTime)
                message = string.format("当前目标：%s，%s，%d/%d", curMainTarget, message, runTime, totalTime)
            else
                message = string.format("当前目标：%s，%s", curMainTarget, message)
            end
        end
        trace.log_trace(message)
        if isMainCtx then
            trace.output(message)
        end
        return bret.SUCCESS
    end
}



return M
